package com.example.demo.controller;

import com.example.demo.pojo.Comment;
import com.example.demo.pojo.Goodsaddguanli;
import com.example.demo.service.CommentServer;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author yanglup
 * @create 2020-12-14 22:35
 */
@Controller
public class BackCommentController {
    @Autowired
    CommentServer commentServer;


    /**查询全部图书*/
    @RequestMapping("/Commentlist")
    public String Commentlist(Model model, HttpServletRequest request) {
        Integer pageNo=request.getParameter("pageNo")==null?1:Integer.valueOf(request.getParameter("pageNo"));
        PageInfo<Comment> pageInfo=commentServer.Commentlist(pageNo,5);
        List<Comment> list=pageInfo.getList();
        model.addAttribute("mycommentlists",list);
        model.addAttribute("pages",pageInfo.getPages());
        model.addAttribute("pageNo",pageInfo.getPageNum());
        model.addAttribute("pageSize",pageInfo.getPageSize());

        Integer allnumber=commentServer.Commentlistnumber();
        model.addAttribute("allnumber",allnumber);
        return "Commentlist";
    }



    /**删除商品*/
    @RequestMapping("/Commentdelete")
    public String Commentdelete(Integer comment_id){
        commentServer.Commentdelete(comment_id);
        return "redirect:/Commentlist";
    }

    /**搜索*/
    @RequestMapping("/Commentlistquery")
    public String Commentlistquery(String comment_text, Model model){
        List<Comment> list=commentServer.Commentlistquery(comment_text);
        model.addAttribute("mycommentlists",list);
        Integer allnumber=commentServer.Commentlistquerynumber(comment_text);
        model.addAttribute("allnumber",allnumber);
        return "Commentlistquery";
    }





}
